<?php
    namespace Home\Controller;

    use \Think\Controller;

    class AttendController extends HomeController
    {
        // 关注用户
        public function attendU()
        {
            $data=array();
            $data['user_id'] = $_SESSION['home']['id'];
            $data['attended_id'] = $_GET['id'];
            // 不存在则添加
            if(M('user_user')->where($data)->select() == null) {
                // $data['datetime'] = date('Y-m-d H:i:s');
                M('user_user')->add($data);
            }
        }

        // 取消关注用户
        public function notAttendU()
        {
            $data['user_id'] = $_SESSION['home']['id'];
            $data['attended_id'] = $_GET['id'];
            // var_dump($data);
            // 删除关注
            M('user_user')->where($data)->delete();
        }


        // 关注话题
        public function attendT()
        {
            $data=array();
            $data['user_id'] = $_SESSION['home']['id'];
            $data['topic_id'] = $_GET['id'];
            // 不存在则添加
            if(M('user_topic')->where($data)->select() == null) {
                // $data['datetime'] = date('Y-m-d H:i:s');
                M('user_topic')->add($data);
                // 给话题表关注数值+1
                M('topics')->where('id='.$data['topic_id'])->setInc('attend_num', 1);
            }
        }

        // 取消话题关注
        public function notAttendT()
        {
            $data['user_id'] = $_SESSION['home']['id'];
            $data['topic_id'] = $_GET['id'];
            // var_dump($data);
            if(M('user_topic')->where($data)->select() != null) {
                M('user_topic')->where($data)->delete();
                // 给话题表关注数值-1
                M('topics')->where('id='.$data['topic_id'])->setDec('attend_num', 1);
            }
        }


    }